﻿/*  
	========================================================================
	 awzBoxes Library
	
	 Homepage: http://www.awzhome.de/
	========================================================================
	
	This Source Code Form is subject to the terms of the Mozilla Public
	License, v. 2.0. If a copy of the MPL was not distributed with this
	file, You can obtain one at http://mozilla.org/MPL/2.0/.
   
	The Original Code is code of awzBoxes Library.

	The Initial Developer of the Original Code is Andreas Weizel.
	Portions created by the Initial Developer are
	Copyright (C) 2011-2012 Andreas Weizel. All Rights Reserved.
	
	Contributor(s): (none)
	
	========================================================================
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;

namespace AWZhome.awzBoxes.Tools
{
	/// <summary>
	/// Helper class for transformation of coordinates.
	/// </summary>
	public static class PointTransformer
	{
		/// <summary>
		/// Converts control-relative <see cref="System.Windows.Point"/> to screen coordinates.
		/// </summary>
		/// <param name="relativePoint"><see cref="System.Windows.Point"/> with relative coordinates.</param>
		/// <param name="relativeTo">The <see cref="System.Windows.Media.Visual"/>
		/// that <paramref name="relativePoint"/> is relative to.</param>
		/// <returns></returns>
		public static Point ConvertToScreen(Point relativePoint, Visual relativeTo)
		{
			// Screen location of upper left corner of Visual
			Point screenPoint = relativeTo.PointToScreen(relativePoint);

			// Transform screen Point to WPF device independent Point
			PresentationSource presentationSource = PresentationSource.FromVisual(relativeTo);
			Point resultPoint = presentationSource.CompositionTarget.TransformFromDevice.Transform(screenPoint);

			return resultPoint;
		}
	}
}
